"""
方案二：采用DS证据理论方法判断
"""
import numpy as np
from numpy import linalg as la


def disToProbability(laser, radar):
    dis = la.norm(laser - radar)
    return dis, 1 / (dis * 10)


def computeProbability(laser, radar):
    Pro = []
    mean = []
    for i in range(radar.shape[0]):
        dis, pro = disToProbability(laser, radar[i])
        mean.append(dis)
        Pro.append(pro)
    Pro.append(1/(np.mean(mean)*10))  # 导入所有概率的平均值作为激光是一个独立目标的概率
    return Pro


def judgeByDS(laser, radar):
    pro_laser = np.array(computeProbability(laser, radar))
    pro_radar = np.array(computeProbability(laser, radar))
    K = 0  # 存储系数K
    MA = []  # 存储h1×h1
    for i in range(len(pro_laser)):
        for j in range(len(pro_radar)):
            if i != j:
                K += pro_laser[i] * pro_radar[j]  # 计算K
            if i == j:
                tem = pro_laser[i] * pro_radar[j]  # 计算h1×h1
                MA.append(tem)
    K = 1 / (1 - 2 * K)
    Bel = []
    for i in MA:
        Bel.append(i * K)  # 计算每个样本的概率
    print(Bel)
    index = Bel.index(max(Bel))
    if index == len(Bel) - 1:
        print("这是一个独立的目标")
        return np.row_stack((radar, laser))
    else:
        print("这是第%d个目标" % (index + 1))
        radar[index] = (radar[index] + laser) / 2
        return radar
